package fun.stgoder.bmwf.auth.controller;

import fun.stgoder.bmwf.auth.service.TestService;
import fun.stgoder.bmwf.core.domain.R;
import fun.stgoder.bmwf.core.domain.dto.Test2DTO;
import fun.stgoder.bmwf.core.exception.BaseException;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;
import java.util.concurrent.TimeUnit;

@RestController
@RequestMapping("/test")
public class TestController {
    @Autowired
    TestService testService;

    @GetMapping("/1")
    R<List<Test2DTO>> test1(@RequestParam(value = "p", required = false) String p) {
        R<List<Test2DTO>> r = testService.f1(p);
        return r;
    }

    @GetMapping("/2")
    String test2() {
        if (true)
            throw new BaseException("test2");
        return "test2";
    }

    @GetMapping("/3")
    String test3() {
        try {
            TimeUnit.SECONDS.sleep(10);
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
        return "test3";
    }
}
